package com.wenguo.bussines.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wenguo.bussines.model.Group;
import com.wenguo.bussines.model.Log;
import com.wenguo.bussines.model.User;
import com.wenguo.bussines.service.FacadeService;
import com.wenguo.bussines.service.GroupService;
import com.wenguo.bussines.service.LogService;
import com.wenguo.bussines.service.UserService;
import com.wenguo.common.util.MD5;
import com.wenguo.exception.WenGuoException;

@Service
public class FacadeServiceImpl implements FacadeService {

	//------------- groupService ---------------------
	private @Autowired GroupService groupService;
	
	@Override
	public List<Group> findAllGroup() throws WenGuoException {
		return groupService.findAllGroup();
	}
	
    @Override
	public Group findGroupById(Integer id) throws WenGuoException {
		return groupService.findGroupById(id);
	}


	//------------- userService ---------------------
	private @Autowired UserService userService;
	@Override
	public Long findCountOfUser(User user) throws WenGuoException {
		return userService.findUserCount(user);
	}
	
	@Override
    public List<User> findUserByPage(Map<Object, Object> map) throws WenGuoException {
    	return userService.findUserByPage(map);
    }
	
    @Override
	public User login(User user) throws WenGuoException {
		List<User> userList = userService.findUserByEntity(user);
		if (userList.size() > 0) {
			User u = userList.get(0);
			if (u.getPass().equals(MD5.code(user.getPass()))) {
				return u;
			}
		}
		return null;
	}
    
	@Override
	public boolean createUser(User user) throws WenGuoException {
		return userService.insertUser(user);
	}
	
	@Override
	public boolean updateUser(User user) throws WenGuoException {
		return userService.updateUser(user);
	}
	
	@Override
	public boolean updateUserPassword(User user) throws WenGuoException {
		return userService.updateUserPwd(user);
	}
	
	@Override
	public User findUserById(String id) throws WenGuoException {
		return userService.findUserById(id);
	}
    
    @Override
	public boolean deleteUserById(String id) throws WenGuoException {
		return userService.deleteUser(id);
	}


	//------------- logService ---------------------
	private @Autowired LogService logService;
	
	@Override
	public Long findCountOfLog(Log log) throws WenGuoException {
		return logService.findLogCount(log);
	}
	
	@Override
	public List<Log> findLogByPage(Map<Object, Object> map) throws WenGuoException {
		return logService.findLogByPage(map);
	}
	
	@Override
	public boolean WriteLog(Log log) throws WenGuoException {
		return logService.insertLog(log);
	}

}
